/*
 * Copyright (c) 2017-2021 duobaoyu, Inc. All rights reserved.<br/>
 * Unless required by applicable law or agreed to in writing, <br/>
 * Unauthorized use and distribution by any person or organization is prohibited.<br/>
 */
package com.shangsi.controller;

import com.shangsi.feignservice.fallback.PaymentFeignService;
import com.shangsi.service.OrderService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author dzd
 * @date 2021-12-26
 */
@RestController
@RequestMapping("limit")
public class OrderLimitRateController {

    @Resource
    private PaymentFeignService paymentFeignService;


    @Resource
    private OrderService orderService;

    @RequestMapping("payment/{id}")
    public String payment(@PathVariable("id") Integer id){

        return paymentFeignService.getPayment(id);
    }

    /**
     * 当payment的qps增加到一定程度之后,对query进行限流, 在query的资源上配置关联
     * @return
     */
    @RequestMapping("query")
    public String orderFeignQuery(){

        return "关联限流配置,当orderFeign的qps超过5时本接口被限流";
    }


    /**
     * 链路1限流
     * @return
     */
    @RequestMapping("linkLimitOne")
    public String linkLimitOne(){
        orderService.queryGoods("链路1");
        return "链路1";
    }


    /**
     * 链路2不限流
     * @return
     */
    @RequestMapping("linkLimitTwo")
    public String linkLimitTwo(){
        orderService.queryGoods("链路2");
        return "链路2";
    }
}
